
//package java_cup;

/**
 * This class represents a Shift actionPart within the parse table. The actionPart
 * simply stores the state that it shifts to and responds to queries about its
 * type.
 *
 * @version last updated: 11/25/95
 * @author Scott Hudson
 */
public class ShiftAction : ParseAction {

    /*-----------------------------------------------------------*/
    /*--- Constructor(s) ----------------------------------------*/
    /*-----------------------------------------------------------*/

    /**
     * Simple constructor.
     * 
     * @param shft_to the state that this actionPart shifts to.
     */
    public ShiftAction(LALRState shftTo) /*throws internal_error*/ {
        /* sanity check */
        if (shftTo == null)
            throw new InternalError("Attempt to create a shift_action to a null state");

        _shift_to = shftTo;
    }

    /*-----------------------------------------------------------*/
    /*--- (Access to) Instance Variables ------------------------*/
    /*-----------------------------------------------------------*/

    /** The state we Shift to. */
    public LALRState _shift_to;

    /** The state we Shift to. */
    public LALRState To => _shift_to;

    /*-----------------------------------------------------------*/
    /*--- General Methods ---------------------------------------*/
    /*-----------------------------------------------------------*/

    /** Quick access to type of actionPart. */
    /*@Override*/
    public int Kind => SHIFT;

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Equality test. */
    public bool equals(ShiftAction other) {
        return other != null && other.To == To;
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Generic equality test. */
    /*@Override*/
    public override bool Equals(Object? other) {
        if (other is ShiftAction)
            return equals((ShiftAction)other);
        else
            return false;
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Compute a hash code. */
    /*@Override*/
    public override int GetHashCode() {
        /* use the hash code of the state we are shifting to */
        return To.GetHashCode();
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Convert to a string. */
    /*@Override*/
    public override string ToString() {
        return "SHIFT(to state " + To.Index + ")";
    }

    /*-----------------------------------------------------------*/

}
